<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑员工</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/temp/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/temp/css/frame.css">

    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <style>
        .out-box{
            background-color: #f3f3f3;
            padding: 15px 0;
            margin-bottom: 20px;
        }
        .layui-upload-img { width: 90px; height: 90px; margin: 0; }
        .pic-more { width:100%; margin: 10px 0px 0px 0px;}
        .pic-more li { width:90px; float: left; margin-right: 5px;}
        .pic-more li .layui-input { display: initial; }
        .pic-more li a { position: absolute; top: 0; display: block; }
        .pic-more li a i { font-size: 24px; background-color: #008800; }
        #slide-pc-priview .item_img img{ width: 90px; height: 90px;}
        #slide-pc-priview li{position: relative;}
        #slide-pc-priview li .operate{ color: #000; display: none;}
        #slide-pc-priview li .toleft{ position: absolute;top: 40px; left: 1px; cursor:pointer;}
        #slide-pc-priview li .toright{ position: absolute;top: 40px; right: 1px; cursor:pointer;}
        #slide-pc-priview li .close{ position: absolute;top: 5px; right: 5px; cursor:pointer;}
        #slide-pc-priview li .closebanner{ position: absolute;top: 5px; right: 35px;cursor:pointer;}
        #slide-pc-priview li .closedet{ position: absolute;top: 5px; right: 5px;cursor:pointer;}
        #slide-pc-priview li:hover .operate{ display: block;position: absolute;width: 90px;height: 90px;background: rgba(255,255,255,0.5);}

        #slide-pc-priview1 .item_img img{ width: 90px; height: 90px;}
        #slide-pc-priview1 li{position: relative;}
        #slide-pc-priview1 li .operate{ color: #000; display: none;}
        #slide-pc-priview1 li .toleft{ position: absolute;top: 40px; left: 1px; cursor:pointer;}
        #slide-pc-priview1 li .toright{ position: absolute;top: 40px; right: 1px;cursor:pointer;}
        #slide-pc-priview1 li .closebanner{position: absolute;top: 5px; right: 5px;cursor:pointer;}
        #slide-pc-priview1 li .closedet{position: absolute;top: 5px; right: 35px;cursor:pointer;}
        #slide-pc-priview1 li:hover .operate{ display: block;position: absolute;width: 90px;height: 90px;background: rgba(255,255,255,0.5);}
    </style>
</head>
<body>           
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>编辑员工</legend>
</fieldset>

<form class="layui-form layui-form-pane" action="" lay-filter="example" style="padding: 20px">
    <input type="hidden" name="id" lay-verify="id" value="{$techn.id}">

    <div class="layui-form-item">
        <label class="layui-form-label">所属店铺</label>
        <div class="layui-input-inline" style="width: 40%">
            <select name="admin_id">
                <option value="{$techn->getData('admin_id')}">{$techn.admin_id.nickname}</option>
                {foreach $shop_list as $k => $v}
                <option value="{$v.id}">{$v.nickname}</option>
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="nickname" lay-verify="nickname" autocomplete="off" value="{$techn.nickname}" placeholder="请输入员工姓名" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 长度1-30个字符
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="phone" lay-verify="phone" value="{$techn.phone}" autocomplete="off" placeholder="请输入员工手机号" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 请输入11位有效手机号
        </div>
    </div>

    <div class="layui-form-item" pane="" style="width: 47.5%">
        <label class="layui-form-label">服务标签</label>
        <div class="layui-input-block">
            {foreach $cate_list as $k => $v}
                {if (in_array($v['id'], $techn['cate_ids']) != false)}
                    <input type="checkbox" name="cate_id" value="{$v.id}" title="{$v.name}" checked>
                {else /}
                    <input type="checkbox" name="cate_id" value="{$v.id}" title="{$v.name}">
                {/if}
            {/foreach}
        </div>
    </div>

    <div class="layui-form-item" pane="" style="width: 47.5%">
        <label class="layui-form-label">擅长项目</label>
        <div class="layui-input-block">
            {foreach $goods_list as $k => $v}
                {if (in_array($v['id'], $check_goods) != false)}
                    <input type="checkbox" name="goods_id" value="{$v.id}" title="{$v.title}" checked>
                {else /}
                    <input type="checkbox" name="goods_id" value="{$v.id}" title="{$v.title}">
                {/if}
            {/foreach}
        </div>
    </div>

    <div class="layui-form-item" id="pics">
        <div class="layui-form-label">优秀作品图</div>
        <div class="layui-input-block" style="width: 70%;">
            <div class="layui-upload">
                <button type="button" class="layui-btn layui-btn-primary pull-left" id="slide-pc">选择多图</button>
                <div class="pic-more">
                    <ul class="pic-more-upload-list" id="slide-pc-priview">
                        {foreach $imgs as $v}
                        <li class="item_img">
                            <div class="operate">
                                <i class="toleft layui-icon"></i>
                                <i class="toright layui-icon"></i>
                                <i class="closebanner layui-icon" srcid="{$v.id}"></i>
                            </div>
                            <img src="{$v.file}" srcid="{$v.id}"  class="img bannerimg" >
                            
                            <input type="hidden" name="pc_src[]" class="input2" value="{$v.file}"/>
                        </li>
                        {/foreach}
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
            <a href="javascript:history.back(-1)" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </div>
</form>
          
<script src="/static/temp/layui/layui.js" charset="utf-8"></script>

<script>
    var img = [];
    layui.use('upload', function(){
        var $ = layui.jquery;
        var upload = layui.upload;

        upload.render({
            elem: '#slide-pc',
            url: '{:url("Techn/imgUpMany")}',
            size: 50000,
            exts: 'jpg|png|jpeg',
            multiple: true,
            before: function(obj) {
                layer.msg('图片上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            },
            done: function(res) {
                img.push(res.data);

                layer.close(layer.msg());  // 关闭上传提示窗口

                if(res.status == 0) {
                    return layer.msg(res.msg);
                }

                $('#slide-pc-priview').append('<li class="item_img"><div class="operate"><i class="toleft layui-icon"></i><i class="toright layui-icon"></i><i  class="close layui-icon"></i></div><img src="' + res.data + '" class="img bannerimg" ><input type="hidden" name="pc_src[]" class="input2" value="' + res.data + '" /></li>');
            }
        });
    });
        
    //点击多图上传的X,删除当前的图片
    $("body").on("click",".closebanner",function(){
        var id = $(this).attr('srcid');
        var that = $(this).closest("li");
        
        $.ajax({
            type: "post",
            url: '{:url("Techn/del_img")}',
            data: {id:id},
            dataType: 'json',
            success: function (res) {
                // layer.close(loading);
                if (res.code == 0) {
                    that.remove();
                }else {
                    layer.msg(res.msg, {
                        icon: 2,
                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        return false;
                    });
                }
            },
            error: function (res) {
                layer.msg("网络错误");
            }
        });
    });

    // 多图上传点击<>左右移动图片
    $("body").on("click", ".pic-more ul li .toleft", function(){
        var li_index = $(this).closest("li").index();

        if(li_index >= 1){
            $(this).closest("li").insertBefore($(this).closest("ul").find("li").eq(Number(li_index)-1));
        }
    });

    $("body").on("click", ".pic-more ul li .toright", function(){
        var li_index = $(this).closest("li").index();
        $(this).closest("li").insertAfter($(this).closest("ul").find("li").eq(Number(li_index) + 1));
    });

    layui.use(['form', 'layedit'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit;

        // 监听提交
        form.on('submit(submit)', function(data){
            let cate_id = '';
            let goods_id = '';

            let img = JSON.stringify([...$(".bannerimg")].map((val,index) => {
                return {
                    url: $(val).attr("src"),
                }
            }))

            $("input[name='cate_id']:checked").each(function(){
                cate_id += $(this).val() + ','
            })

            $("input[name='goods_id']:checked").each(function(){
                goods_id += $(this).val() + ','
            })

            data.field.cate_id = cate_id;
            data.field.goods_id = goods_id;
            data.field.img = img;

            // 加载中样式... 
            let loading = layer.msg('正在修改，请稍后...', {icon: 16, shade: 0.3, time:0});

            $.post('{:url("Techn/setTechnEdit")}', data.field, function(res){
                layer.close(loading);
                    if(res.code == 0){
                        layer.msg(res.msg, {icon: 1,time: 1500}, function(){
                            // window.location.href = "{:url('Techn/techn_list')}";
                            history.back(-1);
                        });
                    }else{
                        layer.msg(res.msg, {icon: 2});
                    }
            })

            return false;
        });
    });
</script>
</body>
</html>